package com.cjkj.hospital.controller;

import com.cjkj.common.annotation.Log;
import com.cjkj.common.annotation.RepeatSubmit;
import com.cjkj.common.core.controller.BaseController;
import com.cjkj.common.core.domain.AjaxResult;
import com.cjkj.common.core.page.TableDataInfo;
import com.cjkj.common.enums.BusinessType;
import com.cjkj.hospital.domain.THospitalUser;
import com.cjkj.hospital.domain.dto.HospitalUserReq;
import com.cjkj.hospital.domain.vo.HospitalUserVo;
import com.cjkj.hospital.service.ITHospitalUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 医院用户Controller
 * 
 * @author cjkj
 * @date 2024-08-28
 */
@RestController
@RequestMapping("/hospital/user")
public class THospitalUserController extends BaseController
{
    @Resource
    private ITHospitalUserService tHospitalUserService;

    /**
     * 查询医院用户列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalUserReq req)
    {
        startPage();
        List<HospitalUserVo> list = tHospitalUserService.selectTHospitalUserList(req);
        return getDataTable(list);
    }

    /**
     * 获取医院用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:user:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId)
    {
        return success(tHospitalUserService.selectTHospitalUserByUserId(userId));
    }

    /**
     * 新增医院用户
     */
    @PreAuthorize("@ss.hasPermi('hospital:user:add')")
    @Log(title = "医院用户", businessType = BusinessType.INSERT)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PostMapping
    public AjaxResult add(@RequestBody @Valid THospitalUser tHospitalUser)
    {
        return toAjax(tHospitalUserService.insertTHospitalUser(tHospitalUser));
    }

    /**
     * 修改医院用户
     */
    @PreAuthorize("@ss.hasPermi('hospital:user:edit')")
    @Log(title = "医院用户", businessType = BusinessType.UPDATE)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PutMapping
    public AjaxResult edit(@RequestBody @Valid THospitalUser tHospitalUser)
    {
        tHospitalUser.setPassword(null);
        return toAjax(tHospitalUserService.updateTHospitalUser(tHospitalUser));
    }

    /**
     * 删除医院用户
     */
    @PreAuthorize("@ss.hasPermi('hospital:user:remove')")
    @Log(title = "医院用户", businessType = BusinessType.DELETE)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable String[] userIds)
    {
        return toAjax(tHospitalUserService.deleteTHospitalUserByUserIds(userIds));
    }

    /**
     * 重置用户密码
     */
    @PreAuthorize("@ss.hasPermi('hospital:user:edit')")
    @Log(title = "医院用户", businessType = BusinessType.UPDATE)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PutMapping("/resetPwd")
    public AjaxResult resetPassword(@RequestBody THospitalUser user)
    {
        return success(tHospitalUserService.resetPassword(user));
    }
}
